package com.json.smtest.SMUtils;

import com.json.smtest.SMUtils.SM2_2.SM2Util;
import com.json.smtest.SMUtils.SM4_2.SM4Utils;

public class SMEnAndEdcodeUtils {

    private static String PUBLICKEYSM2 = "04597cea81267d1e78598714eeb117fc5748914841719e8e11945c5b7e8dc1ceb4a8a7381ea7c6c35d8c78a9f78a65582e6e0ca5267af30e6e068818ea514c1094";
    private static String PRIVATEKEYSM2 = "b09dd8057c50e6e740ad405ab51e5683842744fa402f20bc96d5e34437a8a08c";


    private static String KEYSM4 = "d8f37edaf21f4373";
    private static String IVSM4 = "ed32fb5d34388842";


    /**
     * sm2 公钥加密
     * @param input
     * @return
     */
    public static String encrypt_sm2(String input){
        String encrypt = SM2Util.encrypt(input,PUBLICKEYSM2);
        return encrypt;
    }

    /**
     * sm2 私钥解密
     * @param input
     * @return
     */
    public static String decrypt_sm2(String input){
        String output = SM2Util.decrypt(input, PRIVATEKEYSM2);
        return output;
    }

    /**
     * sm4 cbc模式解密
     * @param input
     * @return
     */
    public static String decrypt_sm4_cbc(String input){
        SM4Utils sm4 = new SM4Utils();
        sm4.hexString=false;
        sm4.secretKey = KEYSM4;
        sm4.iv  = IVSM4;

        String output = sm4.decryptData_CBC(input);
        return output;
    }

    /**
     * sm4 cbc模式
     * @param input
     * @return
     */
    public static String encrypt_sm4_cbc(String input){
        SM4Utils sm4 = new SM4Utils();
        sm4.hexString = false;
        sm4.secretKey = KEYSM4;
        sm4.iv = IVSM4;
        String output = sm4.encryptData_CBC(input);
        return output;
    }
}
